<?

/**
* init the serialization values
*
* @param  string  $COracle  
* @param  string  $userId  
* @param  string  $srcValues
* @param  string  $srcDbHdr
* @param  string  $srcDbDtl
*
*/   
function initSerialize(&$COracle,
                       &$userId,
                       &$srcValues,
                       &$srcDbHdr,
                       &$srcDbDtl){
                        
  
}

/**
* insert to db log
*
* @param  string  $COracle
* @param  string  $today_date
* @param  string  $jobId
* @param  string  $userIp
* @param  string  $operation
* @param  string  $srcDb
*
*/
function insToDbLog(&$COracle,
                    &$today_date,
                    &$jobId,
                    &$userId,
                    $userIp,
                    $operation,
                    &$srcDb){
                      
  fetchLastNoByDate($COracle,
                    $today_date,
                    $srcDb,
                    $lastNo);
  
  $logDate = "TO_DATE('".$today_date."', 'dd-mm-YYYY')";
  
  $values = "  ".$lastNo." , ".
            " '".$jobId."', ".
            " '".$userId."', ".
            "  ".$operation." , ".
            " '".$userIp."', ".
            "  ".$logDate."  ";
              
  $query  = "INSERT INTO ".$srcDb." 
             (NO,
              JOB_ID,
              ENTRIED_BY, 
              OPERATION, 
              IP, 
              TR_DATE)
             VALUES (".$values.") ";
  
  $COracle->execQuery($query);
}

/**
* update the current last no of sequence number
* if the update is failed then it returns to $seqEditStatus
* where true  = success,
*       false = fail.
*
* @param  string  $COracle
* @param  string  $thisSequence
* @param  string  $srcJidIndex
* @param  string  $thisPeriode
* @param  string  $srcDb
* @param  string  $seqEditStatus
*
*/
function initCurSequence(&$COracle,
          	             &$thisSequence,
          	             &$srcJidIndex,
          	             &$thisPeriode,
          	             &$srcDb,
          	             &$seqEditStatus){
  
  $srcPeriode = "TO_DATE('".$thisPeriode."','mm-YYYY')";
  
  $thisIndex  = $srcJidIndex + 1;
  
  /**
  * SEQ_NUMBER is included because
  * we need consistency
  *
  */
  $query  = "UPDATE ".$srcDb." 
             SET SEQ_NUMBER=".$thisIndex." 
             WHERE  SEQ_NAME='".$thisSequence."'
                    AND PERIODE=".$srcPeriode." 
                    AND SEQ_NUMBER=".$srcJidIndex." ";
                    
  $seqEditStatus = $COracle->execQuery($query);
}

/**
* Delete records by jobId
* 
* @param  string  $COracle
* @param  string  $jobId
* @param  string  $srcDb
*
*/
function dbEntDelete(&$COracle,
                     &$jobId,
                     &$srcDb){
                      
  $query  = "DELETE ".$srcDb." 
             WHERE  JOB_ID='".$jobId."' ";
             
  $COracle->execQuery($query);
}

/**
* process the approval
*
* @param  string  $COracle
* @param  string  $apprThisJobId
* @param  string  $refId
* @param  string  $userId
* @param  string  $srcDb
*
*/
function procApproval(&$COracle,
                      &$apprThisJobId,
                      &$refId,
                      &$userId,
                      &$srcDb){

  $query  = "UPDATE ".$srcDb." 
             SET REFERENCE='".$refId."',
                 APPROVED='".$userId."',
                 STATUS='"._ACTIVE."' 
             WHERE  JOB_ID='".$apprThisJobId."' ";
             
  $COracle->execQuery($query);
}

/**
* process the cancelation
*
* @param  string  $COracle
* @param  string  $cclThisJobId
* @param  string  $userId
* @param  string  $srcDb
*
*/
function procCancel(&$COracle,
                    &$cclThisJobId,
                    &$userId,
                    &$srcDb){
  
  $query  = "UPDATE ".$srcDb." 
             SET STATUS='"._CANCELED."',
                 CANCELED='".$userId."'
             WHERE  JOB_ID='".$cclThisJobId."' ";
             
  $COracle->execQuery($query);
}
?>